package com.honeywen.mymvc.opera;

import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author wangwei
 * @date 2019/11/14
 */
public class FileReadTest2 {


    public static void main(String[] args) {
        // 原来
        String filepath = "/Users/wangwei/test/py/august_origin.txt";

        String filepath1 = "/Users/wangwei/test/py/august_group1.txt";
        String filepath2 = "/Users/wangwei/test/py/august_group2.txt";
        String filepath3 = "/Users/wangwei/test/py/august_group3.txt";
        String filepath4 = "/Users/wangwei/test/py/august_group4.txt";
        String filepath5 = "/Users/wangwei/test/py/august_group5.txt";
        String filepath6 = "/Users/wangwei/test/py/august_group6.txt";
        String filepath7 = "/Users/wangwei/test/py/august_group7.txt";


        File file = new File(filepath);
        File file1 = new File(filepath1);
        File file2 = new File(filepath2);
        File file3 = new File(filepath3);
        File file4 = new File(filepath4);
        File file5 = new File(filepath5);
        File file6 = new File(filepath6);
        File file7 = new File(filepath7);


        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

            List<String> list1 = Lists.newArrayList();
            List<String> list2 = Lists.newArrayList();
            List<String> list3 = Lists.newArrayList();
            List<String> list4 = Lists.newArrayList();
            List<String> list5 = Lists.newArrayList();
            List<String> list6 = Lists.newArrayList();
            List<String> list7 = Lists.newArrayList();

            String line = null;
            while ((line = reader.readLine()) != null) {

                line = line.replaceAll("\\s+", " ");
                String[] split = line.split(" ");
                String userId = split[0];
                switch (split[1]) {
                    case "1":
                        list1.add(userId);
                        break;
                    case "2":
                        list2.add(userId);
                        break;
                    case "3":
                        list3.add(userId);
                        break;
                    case "4":
                        list4.add(userId);
                        break;
                    case "5":
                        list5.add(userId);
                        break;
                    case "6":
                        list6.add(userId);
                        break;
                    case "7":
                        list7.add(userId);
                        break;
                    default:
                        break;
                }


            }


            FileUtils.writeLines(file1, list1);
            FileUtils.writeLines(file2, list2);
            FileUtils.writeLines(file3, list3);
            FileUtils.writeLines(file4, list4);
            FileUtils.writeLines(file5, list5);
            FileUtils.writeLines(file6, list6);
            FileUtils.writeLines(file7, list7);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
